import React from "react";
import { Link } from 'react-router-dom';
import { connect } from 'react-redux';

const mapStateToProps = (state) => {
    return {
        name: state.setName.name
    }
}

const mapDispatchToProps = (dispatch) => {
    return {
        setName: () => dispatch({ type: 'SET_NAME' }),
        clearName: () => dispatch({ type: 'CLEAR_NAME' })
    }
  }

class A extends React.Component {
    render() {
        const { name, setName, clearName } = this.props;
        return (
            <div>
                <p>{name}</p>
                <p><button onClick={setName}>获取名字</button><button onClick={clearName}>清除</button></p>
                <p>this is Page A!</p>
                <Link to='/b'>B</Link>
            </div>
        );
    }
}
export default connect(mapStateToProps,mapDispatchToProps)(A);

